using System;
using System.Collections;
using System.Data;
using System.Configuration;
using System.IO;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using ConfigOCR = Dimok.Config.imaging.OCR;
using Dimok.Documents;
using Dimok.Documents.Ocr;

namespace AcrobatObjects {
	public delegate bool OcrProgressDelegate(int pageNumber);
	public delegate void ErrorProgressDelegate(Exception exc);

	public class OCRClient {

		private static RemotePdf ActivateRemotePdf(){	return RemotePdf.ActivateRemotePdf(ConfigOCR.Tcp); }
		#region OcrTiffToPdf ================
		/// <summary>
		/// 
		/// </summary>
		/// <param name="tiffs"></param>
		/// <param name="startPage"></param>
		/// <param name="ocrEngine"></param>
		/// <param name="accuracy"></param>
		/// <param name="ocrProgress">Progress callback (return true to stop process)</param></param>
		/// <param name="errorProgress"></param>
		/// <returns></returns>
		public static byte[][] OcrTiffToPdf(byte[][] tiffs,int startPage,string ocrEngine,string accuracy,OcrProgressDelegate ocrProgress,ErrorProgressDelegate errorProgress) {
			byte[][] pdfs = new byte[tiffs.Length][];
			for(int i=startPage;i<pdfs.Length;i++) {
				try{
					if( ocrProgress != null && ocrProgress(i+1)) return pdfs;
					pdfs[i] = OcrTiffToPdf(tiffs[i],ocrEngine,accuracy);
				}catch(Exception exc) {
					if( errorProgress != null )errorProgress(exc);
					continue;
				}
			}
			return pdfs;
		}
		public static byte[] OcrTiffToPdf(byte[] file){
			return OcrTiffToPdf(file,ConfigOCR.Engine);
		}
		public static byte[] OcrTiffToPdf(byte[] file,string ocrEngine){
			return OcrTiffToPdf(file,ocrEngine,ConfigOCR.Accuracy);
		}
		public static byte[] OcrTiffToPdf(byte[] file,string ocrEngine,string accuracy) {
			return ActivateRemotePdf().OcrTiffToPdf(file,ocrEngine,accuracy);
		}
		#endregion OcrTiffToPdf ================

	}
}